package config

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

const user string = "root"
const passwd string = "123456"
const host string = "192.168.52.132"
const post string = "3306"
const database string = "meiyaa"
const charset string = "utf8mb4"
const parseTime string = "true"

type config struct {
	user     string
	password string
	db       string
}

func getDsn() string {
	//dsn := "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local"
	return user + ":" + passwd + "@tcp(" + host + ":" + post + ")/" + database + "?charset=" + charset + "&parseTime=" + parseTime + "&loc=Local"
}

func Open() *gorm.DB {

	db, err := gorm.Open(mysql.Open(getDsn()), &gorm.Config{})

	if err != nil {
		fmt.Println(err.Error())
	}

	return db
}
